<?php

use App\Enums\DomainSource;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('ssls', function (Blueprint $table) {
            $table->id();
            $table->application();
            $table->enum('type', DomainSource::values());
            $table->unsignedBigInteger('aliyun_id')
                ->index();
            $table->string('rr')
                ->comment('阿里云域名的解析记录')
                ->nullable();
            $table->string('root')
                ->comment('阿里云域名必须的根域名')
                ->nullable();
            $table->string('domain')
                ->comment('自有域名')
                ->nullable();
            $table->string('order_id')
                ->nullable();
            $table->dateTime('expires_at')
                ->comment('订单过期时间')
                ->nullable();
            $table->dateTime('expiry_date')
                ->comment('证书过期时间')
                ->nullable();
            $table->json('certs')
                ->nullable();
            $table->string('state')
                ->nullable()
                ->comment('当前状态');
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('ssls');
    }
};
